package com.xcode.xandrdb.Executer;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import android.app.Application;
import android.util.Log;

import com.xcode.xandrdb.Catch.TransationCatch;
import com.xcode.xandrdb.Executer.Util.ExecuterCore;
import com.xcode.xandrdb.annotation.Transation;
import com.xcode.xandrdb.interfaces.HandlerExecuter;
import com.xcode.xandrdb.sqlite.SqliteHelper;

public class DeleteExecuter implements HandlerExecuter
{
	@Override
	public Object execute(InvocationHandler handler, Object proxy, Method method, Object[] args,Application session,String annotationValue)
	{
		long key = System.currentTimeMillis();
		SqliteHelper sqLiteDatabase = null;
		String sql = ExecuterCore.getNativeSQl(annotationValue, method, args);
		if(method.isAnnotationPresent(Transation.class))
		{
			TransationCatch.getInstance().add(sql);
			return null;
		}
		try
		{
			sqLiteDatabase = SqliteHelper.getInstance();
			sqLiteDatabase.execSQL(sql);
			Log.i("XAndrDB","ExecuteSql:" + sql);
		} catch (Exception e)
		{
			e.printStackTrace();
		}finally 
		{
			if (sqLiteDatabase != null)
			{
				sqLiteDatabase.close(key);
			}
		}
		return null;
	}
}
